﻿
@{
    ViewBag.Title = "EventsDelegatesLambdas";
}

<h2>Events, Delegates and Lambdas</h2>

<div class="panel panel-default">
    <div class="panel-heading">
        <div class="panel-title">Introduction</div>
    </div>
    <div class="panel-body">
        <img src="~/Images/Events.png" alt="Events" />
    </div>
</div>

<div class="panel panel-default">
    <div class="panel-heading">
        <div class="panel-title">Creating A Delegate</div>
    </div>
    <div class="panel-body">
        <p>
            Delegates are essentially <em>blueprints</em> of event handlers.
            <code>
                public delegate void Notify(string message);
            </code>
            Now, there can be many methods defined in classes, for example:
            @Html.DisplayCode(@"
                    public class NewsChannel
                    {
                        public void NotifyPeople(string message)
                        {
                            //Notify people via News broadcast
                        }
                    }
                    public class NewsOnline
                    {
                        public void NotifySubscribers(string message)
                        {
                            //Notify subscribers
                        }
                    }
                ", "C#")
                The <code>NotifyPeople</code> &amp; <code>NotifySubscribers</code> methods are suitable <em>Event handlers</em> for our delegate.
                Its the method return type &amp; method parameters that must be same for an <em>Event handler</em> and a delegate, in order to bind them.
            </p>
        </div>
    </div>
    <div class="panel panel-default">
        <div class="panel-heading">
            <div class="panel-title">Defining an Event</div>
        </div>
        <div class="panel-body">
            Test
        </div>
    </div>
    <div class="panel panel-default">
        <div class="panel-heading">
            <div class="panel-title">Raising Events</div>
        </div>
        <div class="panel-body">

        </div>
    </div>
    <div class="panel panel-default">
        <div class="panel-heading">
            <div class="panel-title">Creating an EventArgs Class</div>
        </div>
        <div class="panel-body">

        </div>
    </div>